package com.liunian.algorithmstudy.tree;

public class SearchBST700 extends TreeNode {

	public TreeNode searchBST(TreeNode root, int val) {
		if (root == null) {
			return null;
		}
		if (root.val == val) {
			return root;
		}
		TreeNode leftTree = searchBST(root.left, val);
		if (leftTree != null && leftTree.val == val) {
			return leftTree;
		}
		TreeNode rightTree = searchBST(root.right, val);
		if (rightTree != null && rightTree.val == val) {
			return rightTree;
		}
		return null;
	}

}
